#!/bin/bash

FWPATH="../../../ARM/STM_Eclipse/BLDC_4_ChibiOS"
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

################## HW46_47 #######################

rm hw_46_47/*

# default
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DHW_VERSION_46"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_46_47/VESC_default.bin

# 33k
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DVIN_R1=33000.0 -DHW_VERSION_46"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_46_47/VESC_33k.bin

# 0005ohm
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DCURRENT_SHUNT_RES=0.0005 -DHW_VERSION_46"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_46_47/VESC_0005ohm.bin

# ws2811
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DWS2811_ENABLE=1 -DHW_VERSION_46"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_46_47/VESC_ws2811.bin

# ws2811_33k
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DWS2811_ENABLE=1 -DVIN_R1=33000.0 -DHW_VERSION_46"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_46_47/VESC_ws2811_33k.bin

# servoout
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DSERVO_OUT_ENABLE=1 -DHW_VERSION_46"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_46_47/VESC_servoout.bin

#################### HW_48 ########################

rm hw_48/*

# default
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DHW_VERSION_48"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_48/VESC_default.bin

# 0005ohm
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DCURRENT_SHUNT_RES=0.0005 -DHW_VERSION_48"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_48/VESC_0005ohm.bin

# ws2811
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DWS2811_ENABLE=1 -DHW_VERSION_48"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_48/VESC_ws2811.bin

# servoout
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DSERVO_OUT_ENABLE=1 -DHW_VERSION_48"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_48/VESC_servoout.bin

#################### HW_410_411_412 ########################

rm hw_410_411_412/*

# default
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DHW_VERSION_410"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_410_411_412/VESC_default.bin

# 0005ohm
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DCURRENT_SHUNT_RES=0.0005 -DHW_VERSION_410"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_410_411_412/VESC_0005ohm.bin

# ws2811
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DWS2811_ENABLE=1 -DHW_VERSION_410"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_410_411_412/VESC_ws2811.bin

# servoout
cd $FWPATH
touch conf_general.h
make -j4 build_args="-DSERVO_OUT_ENABLE=1 -DHW_VERSION_410"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin hw_410_411_412/VESC_servoout.bin

# Clean
cd $FWPATH
make clean
cd $DIR

